#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N=2e5+10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//

//int a[N];
int n;
void solve()
{
	cin>>n;
	vector<int> a[n+1];
	map<int,int> cnt;
	
	int pos=0;
	for(int i=1;i<=n;i++)
	{
		int q,id;
		cin>>q;
		
		while(q--)
		{
			cin>>id;
			cnt[id]++;
			//a[++pos]=id;
			a[i].push_back(id);
		}
	}
	
	vector<int> ans;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<a[i].size();j++) cnt[a[i][j]]--;
		for(int j=0;j<a[i].size();j++)
		{
			if(!cnt[a[i][j]]) 
			{
				ans.push_back(a[i][j]);
				break;
			}
		}
	}
	
	if(ans.size()==n)
	{
		for(auto &k : ans) cout<<k<<" ";
		cout<<'\n';
	}
	else cout<<-1<<'\n';

}

int main()
{
	close();
	int T; cin>>T;
	while (T--) solve();
	return 0;
}

